/**
 * FtpTaskEditor.java
 * @author Daniel Liu
 * Create: 2007-1-4 ����10:30:41
 * NOTE: 
 */
package org.lex.ftp.ui.queue;

import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JDialog;
import javax.swing.JTabbedPane;

import org.lex.ftp.queue.Task;
import org.lex.swing.ActionBuilder;
import org.lex.swing.util.Buttons;
import org.lex.swing.util.CenterSouthPane;
import org.lex.swing.widgets.EnhancedDialog;


public class TaskEditorDialog extends EnhancedDialog {
	private JTabbedPane tabbedPane = null;
	private Buttons buttonsPane = null;
	private TaskEditorPane sourcePane = null;
	private TaskEditorPane targetPane = null;

	public static void main(String[] args) {
		TaskEditorDialog dialog = new TaskEditorDialog(null);
		dialog.setLocationRelativeTo(null);
		dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		dialog.setVisible(true);
	}

	public TaskEditorDialog() {
		super();
		initialize();
	}

	public TaskEditorDialog(Window owner) {
		super(owner);
		initialize();
	}

	public void setTask(Task task) {
		this.getSourcePane().setSource(task);
		this.getTargetPane().setTarget(task);
	}

	public void ok() {
	}

	public void cancel() {
		dispose();
	}

	// =======================
	private void initialize() {
		this.setSize(425, 245);
		this.setTitle("Queue Editor");
		this.setModal(true);
		this.setContentPane(new CenterSouthPane(this.getTabbedPane(), this.getButtonsPane()));
		this.setDefaultButton(this.getButtonsPane().getButton(0));
	}

	private JTabbedPane getTabbedPane() {
		if (tabbedPane == null) {
			tabbedPane = new JTabbedPane();
			tabbedPane.addTab("Source", null, getSourcePane(), null);
			tabbedPane.addTab("Target", null, getTargetPane(), null);
		}
		return tabbedPane;
	}

	private Buttons getButtonsPane() {
		if (buttonsPane == null) {
			buttonsPane = Buttons.trailing(new ActionBuilder("OK").setActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					ok();
				}
			}), new ActionBuilder("Cancel").setActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					cancel();
				}
			}));
		}
		return buttonsPane;
	}

	private TaskEditorPane getSourcePane() {
		if (sourcePane == null) {
			sourcePane = new TaskEditorPane();
		}
		return sourcePane;
	}

	private TaskEditorPane getTargetPane() {
		if (targetPane == null) {
			targetPane = new TaskEditorPane();
		}
		return targetPane;
	}
}
